﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Index2.Master" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
收费服务
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="HeadContent" runat="server">
    <script type="text/javascript">
        var id = 'ServiceNo';
        var ctrlName = 'CheckoutService';
        function Crud2(id, ctrlName) {
            //根据死者编号或姓名查询，查询的结果不分页
            this.Search = function () {
                var form = $('#fm');
                if (!$(form).form('validate')) {
                    return;
                }
                url = '../' + ctrlName + '/Search';
                var data = $(form).serialize();
                $.post(url, data, function (result) {
                    if (result.success) {                        
                        $('#dg').datagrid('loadData', result.msg);        // reload the user data
                    } else {
                        $.messager.show({
                            title: '错误',
                            msg: result.msg
                        });
                    }
                });
            };
            //收费
            this.Charge = function () {
                var ids = [];
                var rows = $('#dg').datagrid('getRows');
                var totals = new Number();
                for (var i = 0; i < rows.length; i++) {
                    if (rows[i]['PayStatus']) continue;
                    ids.push(rows[i][id]);
                    totals += rows[i]['ServiceFee'];
                }
                if (ids.length < 1) {
                    $.messager.alert('提示', '没有费用可收!', 'info');
                    return;
                }
                var msg = '应收费用：' + totals + ' 元';
                $.messager.confirm('Confirm', msg , function (r) {
                    if (r) {
                        $.post('../' + ctrlName + '/Pay', { ids: ids.join("&") }, function (result) {
                            if (result.success) {
                                $('#dg').datagrid('loadData', result.msg);
                                $.messager.show({
                                    title: '提示',
                                    msg: '收费完成！'
                                });
                            } else {
                                $.messager.show({	// show error message
                                    title: '错误',
                                    msg: result.msg
                                });
                            }
                        }, 'json');
                    }
                });
            };
            //打印死者费用明细
            this.Print = function () {
                var form = $('#fm');
                if (!$(form).form('validate')) {
                    return;
                }
                var data = $(form).serialize();

                var ids = [];
                var rows = $('#dg').datagrid('getRows');
                var totals = new Number();
                for (var i = 0; i < rows.length; i++) {
                    ids.push(rows[i][id]);
                    totals += rows[i]['ServiceFee'];
                }
                if (ids.length < 1) {
                    $.messager.alert('提示', '没有内容可印!', 'info');
                    return;
                }
                var url = '../' + ctrlName + '/PrintDeadFeeList?' + data;
                ShowDialog(url,'PrintDeadFeeList', '800px', '600px');
            };
        }
        var crud = new Crud2(id, ctrlName);
        $(function () {
            $('#dg').datagrid({
                title: '死者费用列表',
                iconCls: 'icon-save',
                url: '../' + ctrlName + '/List',
                sortName: id,
                sortOrder: 'asc',
                remoteSort: false,
                idField: id,
                frozenColumns: [[
	                { field: 'ck', checkbox: true },
	                { title: '编号', field: id, width: 80, sortable: true },
                    { field: 'DeadNO', title: '死者编号', width: 80 }
				]],
                columns: [[
                        { field: 'DeadName', title: '死者姓名', width: 80 },
                        { field: 'ItemName', title: '服务名称', width: 150 },
                        { field: 'Unit', title: '计量单位', width: 80 },
                        { field: 'Price', title: '价格', width: 80 },
                        { field: 'ServiceCount', title: '数量', width: 80 },
                        { field: 'ServiceFee', title: '费用', width: 100 },
                        { field: 'ApplyTime', title: '申请时间', width: 150,
                            formatter: function (value) {
                                return JsonToDateString(value, 'yyyy-MM-dd hh:mm:ss');
                            }
                        },
                        { field: 'PayStatus', title: '是否支付', width: 80,
                            formatter: function (value) {
                                return value ? '<span style="color:blue">已付</span>' : '<span style="color:red">未付</span>';
                            }
                        },
                        { field: 'PayTime', title: '支付时间', width: 150,
                            formatter: function (value) {
                                return JsonToDateString(value, 'yyyy-MM-dd hh:mm:ss');
                            }
                        },
                        { field: 'Salesman', title: '业务员', width: 100 },
                        { field: 'Cashier', title: '收银员', width: 100 }
                    ]],
                pagination: false,
                fitColumns: true,
                toolbar: '#tb'
            });
        });         
    </script>
</asp:Content>

<asp:Content ID="Content3" ContentPlaceHolderID="MainContent" runat="server">
    <div id="dlg" class="easyui-dialog" closed="true" buttons="#dlg-buttons" 
			style="width:800px;height:480px;padding:10px 20px">
		<div class="ftitle">死者信息</div>
	</div>
    <div id="tb" style="padding:5px;height:auto">          
        <div>  
            <form id="fm">
            死者编号: <input name="DeadNO"   class="easyui-validatebox" style="width:80px" />  
            <%//死者姓名: <input name="DeadName" class="easyui-validatebox" style="width:80px" /> %>               
            <a href="#" class="easyui-linkbutton" iconCls="icon-search" onclick="crud.Search()">查询</a> 
            <a href="#" class="easyui-linkbutton" iconCls="icon-ok" onclick="crud.Charge()">收费</a> 
            <a href="#" class="easyui-linkbutton" iconCls="icon-print" onclick="crud.Print()">打印</a>
            </form> 
        </div>  
    </div>  
</asp:Content>


